
package com.kanjian.music.fragment;

import java.util.ArrayList;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.kanjian.music.R;
import com.kanjian.music.activity.BaseActivity;
import com.kanjian.music.adapter.NoAvatarMusicListListAdapater;
import com.kanjian.music.constants.IntentConstants;
import com.kanjian.music.entity.Music;

public class NoAvatarMusicListFragment extends BaseFragment {

    public static NoAvatarMusicListFragment newInstance(ArrayList<Music> musicList) {
        Bundle b = new Bundle();
        b.putSerializable(IntentConstants.MUSICLIST, musicList);
        NoAvatarMusicListFragment f = new NoAvatarMusicListFragment();
        f.setArguments(b);
        return f;
    }

    private View mRootView;

    private ArrayList<Music> mMusicList;

    private ListView mListView;

    private NoAvatarMusicListListAdapater mListAdapater;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle b = getArguments();
        if (b != null) {
            mMusicList = (ArrayList<Music>) b.getSerializable(IntentConstants.MUSICLIST);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        initView(inflater);
        return mRootView;
    }

    private void initView(LayoutInflater inflater) {
        if (mRootView == null) {
            mRootView = inflater.inflate(R.layout.fragment_musician_music_list, null);
        }
        mListView = (ListView) mRootView.findViewById(R.id.musiclist_listview);
        mListAdapater = new NoAvatarMusicListListAdapater((BaseActivity) getActivity(), mListView,
                mMusicList);
        mListView.setAdapter(mListAdapater);
    }

    public void setMusicList(ArrayList<Music> musicList) {
        this.mMusicList = musicList;
        this.mListAdapater.setMusicList(mMusicList);
    }

}
